home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Files / MoreIsBetter / MIB-Libraries / Sources / MoreWindows.cp < prev   
Encoding:
Text File  |  1998-09-25  |  2.2 KB  |  102 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        MoreWindows.cp
  3.  
  4.     Contains:    
  5.  
  6.     Written by:    Pete Gontier (PCG)
  7.  
  8.     Copyright:    Copyright (c) 1998 Apple Computer, Inc.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>     7/24/98    PCG        eliminate dependency on 'qd'
  13.          <1>     6/16/98    PCG     initial checkin
  14. */
  15.  
  16.  
  17. #include "MoreQuickDraw.h"
  18. #include "MoreWindows.h"
  19. #include "MoreAppearance.h"
  20.  
  21. #include <Controls.h>
  22. #include <Menus.h>
  23.  
  24. pascal OSStatus MoveWindowToAlertPosition (WindowRef window)
  25. {
  26.     OSStatus err = noErr;
  27.  
  28.     if (!MoreAssert (HaveAppearance ( ) || IsWindowVisible (window)))
  29.         err = paramErr;
  30.     else
  31.     {
  32.         Rect screenRect = (**GetMainDevice ( )).gdRect;
  33.         screenRect.top += GetMBarHeight ( );
  34.         InsetRect (&screenRect,4,4);
  35.  
  36.         Rect contRect;
  37.  
  38.         if (!HaveAppearance ( ) || IsWindowVisible (window))
  39.             contRect = (**(((WindowPeek)window)->contRgn)).rgnBBox;
  40.         else
  41.         {
  42.             RgnHandle contRgn = NewRgn ( );
  43.  
  44.             if (!contRgn)
  45.                 err = QDError ( );
  46.             else
  47.             {
  48.                 err = GetWindowRegion (window,kWindowContentRgn,contRgn);
  49.  
  50.                 contRect = (**contRgn).rgnBBox;
  51.  
  52.                 DisposeRgn (contRgn);
  53.                 (void) MoreAssert (noErr == QDError ( ));
  54.             }
  55.         }
  56.  
  57.         if (!err)
  58.         {
  59.             Point windLoc;
  60.  
  61.             windLoc.v    = screenRect.top + ((screenRect.bottom - screenRect.top) / 3);
  62.             windLoc.h    = screenRect.left + ((screenRect.right - screenRect.top) / 2);
  63.  
  64.             windLoc.v    -= (contRect.bottom - contRect.top) / 2;
  65.             windLoc.h    -= (contRect.right - contRect.left) / 2;
  66.  
  67.             MoveWindow (window, windLoc.h, windLoc.v, true);
  68.         }
  69.     }
  70.  
  71.     return err;
  72. }
  73.  
  74. pascal OSErr MoreNewWindow (    const Rect *            boundsRect,
  75.                                 ConstStr255Param         title,
  76.                                 short                     theProc,
  77.                                 Boolean                 goAwayFlag,
  78.                                 long                     refCon,
  79.                                 WindowRef                *window            )
  80. {
  81.     OSErr err = noErr;
  82.  
  83.     if (!title)
  84.         title = "\p";
  85.  
  86.     if (HaveColorQuickDraw ( ))
  87.         *window = NewCWindow (nil,boundsRect,title,false,theProc,(WindowRef)kFirstWindowOfClass,goAwayFlag,refCon);
  88.     else
  89.         *window = NewWindow (nil,boundsRect,title,false,theProc,(WindowRef)kFirstWindowOfClass,goAwayFlag,refCon);
  90.  
  91.     if (!*window)
  92.         err = nilHandleErr;
  93.     else if (HaveAppearance ( ))
  94.     {
  95.         ControlRef dontCare;
  96.         err = CreateRootControl (*window,&dontCare);
  97.         if (err) DisposeWindow (*window);
  98.     }
  99.  
  100.     return err;
  101. }
  102.